/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.ujf.sharepas.impl;



import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.core.internal.resources.File;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.jobs.ISchedulingRule;

import edu.ujf.sharepas.impl.Constante.Right;


/**
 *
 * @author yaiba
 */
public class ShareFile implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1874466121646845492L;
	private transient IFile file;
	private java.io.File fileContent ;

	Right right;
	List<String> avis;

	public ShareFile(String filePath, Constante.Right r){
		
		IWorkspace ws = ResourcesPlugin.getWorkspace();
		IProject project = ws.getRoot().getProject("External Files");
		try {
		if (!project.exists())
				project.create(null);
		
		if (!project.isOpen())
				project.open(null);
			
		IPath location = new Path(filePath);
		this.file = project.getFile(location.lastSegment());
		this.fileContent = new java.io.File(filePath);
		if(!file.exists()){
			this.file.create(new FileInputStream(filePath),true,null);
		}else{
			this.file = ResourcesPlugin.getWorkspace().getRoot().getFile(location);
		}

		} catch (Exception e) {
			e.printStackTrace();
		}
		this.right = r;
		this.avis = new ArrayList<String>();
	
	}

	public IFile getIFile(){
		try {
			FileInputStream in = new FileInputStream(fileContent);
			file.create(in, true, null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return file;
		
	}
	
	public java.io.File getFileContent() {
		return fileContent;
	}

	public Right getRight(){
		return this.right;
	}


}
